<template>
  <div v-loading="loading" class="account-box">
    <el-form ref="form" :model="form" label-width="120px">
      <el-form-item>
        <el-alert
          :closable="false"
          title="注：开关打开时,当有新的订单进入,相应提醒人将收到短信通知。"
          type="info"/>
      </el-form-item>
      <el-form-item label="提醒人-1">
        <el-switch v-model="form.remind1['status']"/>
        <el-input v-model="form.remind1['value']" :disabled="!form.remind1['status']" maxlength="11" placeholder="请输入手机号码"/>
      </el-form-item>
      <el-form-item label="提醒人-2">
        <el-switch v-model="form.remind2['status']"/>
        <el-input v-model="form.remind2['value']" :disabled="!form.remind2['status']" maxlength="11" placeholder="请输入手机号码"/>
      </el-form-item>
      <el-form-item label="提醒人-3">
        <el-switch v-model="form.remind3['status']"/>
        <el-input v-model="form.remind3['value']" :disabled="!form.remind3['status']" maxlength="11" placeholder="请输入手机号码"/>
      </el-form-item>
      <el-form-item label="提醒人-4">
        <el-switch v-model="form.remind4['status']"/>
        <el-input v-model="form.remind4['value']" :disabled="!form.remind4['status']" maxlength="11" placeholder="请输入手机号码"/>
      </el-form-item>
      <el-form-item label="提醒人-5">
        <el-switch v-model="form.remind5['status']"/>
        <el-input v-model="form.remind5['value']" :disabled="!form.remind5['status']" maxlength="11" placeholder="请输入手机号码"/>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="onSubmit()">保存</el-button>
        <el-button @click="$router.back()">取消</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
  export default {
    props: {},
    data() {
      return {
        loading: false,
        // 提醒设置
        form: {
          remind1: {
            status: false,
            value: ''
          },
          remind2: {
            status: false,
            value: ''
          },
          remind3: {
            status: false,
            value: ''
          },
          remind4: {
            status: false,
            value: ''
          },
          remind5: {
            status: false,
            value: ''
          }
        }
      }
    },
    mounted() {
      this.loadData();
    },
    methods: {
      // 加载数据
      loadData(){
        (async () => {
          this.loading = true;
          const result = await this.$service.applicationGetOrderRemindSetting();
          this.loading = false;
          if (result.code === 0) {
            const temp = result.data;
            temp['remind1'].status = !!temp['remind1'].status;
            temp['remind2'].status = !!temp['remind2'].status;
            temp['remind3'].status = !!temp['remind3'].status;
            temp['remind4'].status = !!temp['remind4'].status;
            temp['remind5'].status = !!temp['remind5'].status;
            this.form = Object.assign(this.form, temp || {});
          }
        })();
      },

      // 提交
      onSubmit() {
        this.$refs.form.validate(valid => {
          if (valid) {
            (async () => {
              const params = Object.assign({}, this.form);
              const result = await this.$service.applicationUpdateOrderRemindSetting(params);
              if (result.code === 0) {
                this.$message.success('操作成功~');
              } else {
                this.$message.error(result.msg);
              }
            })();
          } else {
            console.log('error submit!!');
            return false;
          }
        });
      }
    }
  }
</script>
